package com.example.androidlogin;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {
    private List<Integer> list_iv;
    private List<String> list_tv1;
    private List<String> list_tv2;
    private List<String> list_tv3;
    private Context mContext;

    public RecyclerViewAdapter(List<Integer> list_iv, List<String> list_tv1, List<String> list_tv2, List<String> list_tv3, Context mContext) {
        this.list_iv = list_iv;
        this.list_tv1 = list_tv1;
        this.list_tv2 = list_tv2;
        this.list_tv3 = list_tv3;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_fragment, viewGroup, false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        myViewHolder.list_fragment_iv.setImageResource(list_iv.get(i));
        myViewHolder.list_fragment_tv1.setText(list_tv1.get(i));
        myViewHolder.list_fragment_tv2.setText(list_tv2.get(i));
        myViewHolder.list_fragment_tv3.setText(list_tv3.get(i));
    }

    @Override
    public int getItemCount() {
        return list_iv.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView list_fragment_iv;
        TextView list_fragment_tv1;
        TextView list_fragment_tv2;
        TextView list_fragment_tv3;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            list_fragment_iv = itemView.findViewById(R.id.list_fragment_iv);
            list_fragment_tv1 = itemView.findViewById(R.id.list_fragment_tv1);
            list_fragment_tv2 = itemView.findViewById(R.id.list_fragment_tv2);
            list_fragment_tv3 = itemView.findViewById(R.id.list_fragment_tv3);
        }
    }
}
